from fastapi import APIRouter, Query
from tortoise.expressions import Q
from app.controllers.goods.brand import brand_controller
from app.schemas.base import Success, SuccessExtra,Fail


mini_goods_brand_router = APIRouter()
model_name = "品牌"


@mini_goods_brand_router.get("/list", summary=f"查看{model_name}列表")
async def do_list(
        page: int = Query(1, description="页码"),
        page_size: int = Query(10, description="每页数量"),
        name: str = Query(None, description=f"{model_name}名称"),
):
    q = Q()
    if name:
        q &= Q(name__contains=name)
    total, data = await brand_controller.do_list(page=page, page_size=page_size, search=q)
    return SuccessExtra(data=data, total=total, page=page, page_size=page_size)
